package com.fauks.ssm.springmvc.swagger;

import com.fauks.ssm.entity.Person;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

/**
 * 通过添加相应注解实现API与文档同步的效果
 */
@Api(value = "API") //用在类上表明可供Swagger展示的接口类
@RestController
@RequestMapping("/sw")
public class SwaggerController {

    @ApiOperation(value = "测试Swagger文档", httpMethod = "GET",
            produces = "application/json", protocols = "HTTP",
            response = Person.class, notes = "简单测试一下Swagger的用法" +
            "<p>成功：success = ‘true’ | 失败：success = ‘false’ 并返回错误码，如下：</p>" +
            "<p>错误码：</p>" +
            "<p>10201 : hotelId不能为空 </p>" +
            "<p>10202 : 系统异常,获取失败</p>")//描述API方法，用在
    @RequestMapping("/personList")
    public List<Person> getPersonList(@ApiParam(required = true, name = "source", value = "客户来源")
                                              String source) {
        System.out.println(source);
        return Arrays.asList(new Person("fauks", "男", "青岛")
                , new Person("slx", "女", "威海")
                , new Person("周杰伦1", "男", "台北")
                , new Person("Mj", "男", "美国")
        );
    }
}
